import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
// 创建store
const store = new Vuex.Store({
  state: {
    num: 10
  },
  actions: {
    add_num_async ({ commit }, n) {
      setTimeout(() => {
        commit('add_num', n)
      }, 2000)
    }
  },
  mutations: {
    add_num (state, n) {
      console.log('触发了')
      state.num += n
    },
    reduce_num (state, n) {
      state.num -= n
    }
  }
})

export default store
